package com.jm.weibo.util;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;

import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.util.Log;

public class LoadImageUtil {
  
	public static BitmapDrawable loadImageFromNet(URL url){
		   //从网络获取用户的头像
	   BitmapDrawable bd = null;
		try {
			bd = NetUtil.getImageFromURL(url);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return bd;
	}
	
	public static Drawable loadIBitmapDrawable(String urlStr){
		Drawable drawable = null;
		try {
			if(urlStr == null || urlStr.length() == 0){
				System.out.println("----------图片地址不对吧 都是空的----------");
			}
			URL url = new URL(urlStr);
			InputStream inputStream = (InputStream) url.getContent();
			drawable = Drawable.createFromStream(inputStream, "src");
			
		} catch (MalformedURLException e) {
			Log.e("ERROR", "图片地址转换出错, 地址为：" + urlStr);
			
			e.printStackTrace();
		} catch (IOException e) {
			Log.e("ERROR", "获取图片出错");
			e.printStackTrace();
		}
		
		return drawable;
	}
}
